<!--  -->
<template>
  <div class="">
    <el-form ref="form" :model="form" label-width="80px">
      
      <el-form-item label="姓名" prop="name">
        <el-input  v-model="form.name" placeholder="请输入请假人姓名" disabled="true"></el-input>
      </el-form-item>
      <el-form-item label="请假原因">
        <el-input  v-model="form.desc"  type='textarea' placeholder="请输入请假原因"></el-input>
      </el-form-item>
      <el-form-item label="开始时间" prop="time">
        <el-col>
          <el-date-picker
          type="datetimerange"
            placeholder="选择日期"
            v-model="time"
            value-format="yyyy-MM-dd hh:mm:ss"
            style="width: 100%"
          ></el-date-picker>
        </el-col>
        <!-- {{ time }} -->
      </el-form-item>
      <el-form-item label="总计时间">
        <el-input  v-model="form.total" disabled></el-input>
      </el-form-item>
  
      <el-form-item label="请假状态">
        <el-input  v-model="form.status" disabled></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">提交申请</el-button>
        <el-button @click="cancel('form')">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
    
<script>
import {addLeaveList} from '@/api'
export default {
  components: {},
  data() {
    return {
      form: {
        status:'申请中',
        name:JSON.parse(localStorage.getItem('userInfo')).nick,
        start:'',
        end:'',
        desc:'',
        time:'',
        total:''
      },
     time:''
    };
  },
  computed: {
 
  },
  watch: {
    time(newVal,oldVal){
      
        let start = new Date(newVal[0].replace(/-g/,"/"))
        let end = new Date(newVal[1].replace(/-g/,"/"))
       this.form.start=newVal[0]
       this.form.end=newVal[1]
       this.form.status=-1
          return this.form.total=(parseInt(end-start)/1000/60/60)
      },immediate:true,deep:true
    
      
     
    
   
  },
  methods: {
    cancel(form){
       this.$refs[form].resetFields();
    },
    onSubmit(){
      let data={
           userId:  JSON.parse(localStorage.getItem('userInfo')).id,
           start:this.form.start,
           end:this.form.end,
           total:this.form.total,
           status:this.form.status,
           des: this.form.desc,
           remainningDays:3,
           nick: JSON.parse(localStorage.getItem('userInfo')).nick

      }
      addLeaveList(data).then(res=>{
        console.log(res)
        if(res.code==200){
          this.$message.success('提交成功')
        }else{
          this.$message.error('提交失败')
        }
      })
    
    }
  },
  created() {},
  mounted() {},
  beforeCreate() {},
  beforeMount() {},
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroyed() {},
  activated() {},
};
</script>
    <style  scoped>
</style>